Adding support for putting the warning string at index of problem #1406
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Configurable Warning Message Placement
Summary
This change adds a new configuration option
InsertWarningAtProblemLocationthat controls where warning messages are placed in sanitized strings. When enabled, warnings are inserted at the problem location (right before the detected pattern) instead of being prepended to the beginning of the string.Motivation
Previously, all warning messages were prepended to the beginning of strings, which could make it difficult to understand the context of the detected issue. By inserting warnings at the exact location where the problem was detected, users get better context about what triggered the sanitizer.
Example Behavior
Input:
"User accessed https://evil.com/secret"Pattern detected:
https://evil.comat index 14Before (default behavior -
InsertWarningAtProblemLocation = false):"WARNING: aka.ms/ODSPSanitizerURL User accessed https://evil.com/secret"
After (when enabled -
InsertWarningAtProblemLocation = true):"User accessed WARNING: aka.ms/ODSPSanitizerURL https://evil.com/secret"
Implementation Details
Core C++ Changes
InsertWarningAtProblemLocationboolean field toSanitizerConfiguration(default:false)HandleWarningMessageto accept amatchIndexparameter indicating where the pattern was foundCreateWarningMessage(prefix, str, offset)alongside existingCreateWarningMessage(prefix, str)InsertWarningAtProblemLocation == trueandmatchIndex > 0, the new 3-parameter overload is calledCross-Platform Support
Configuration propagates through all platform layers:
SanitizerConfiguration.java,Sanitizer.java, andSanitizer_jni.cppODWSanitizerInitConfig.hand.mmSanitizerInitConfig.swiftwrapperEdge Case Handling
offset == 0: Falls back to prepend behavioroffset >= string.length(): Falls back to prepend behaviorTesting
Added comprehensive unit tests:
Backwards Compatibility
✅ Fully backwards compatible - default value is
false, maintaining existing prepend behavior✅ Existing code that doesn't set this configuration field continues to work unchanged
✅ No breaking changes to any public APIs
Technical Notes
std::memcpy,resize(), pointer arithmetic)Files Modified
Core C++ (5 files)
lib/modules/sanitizer/SanitizerConfiguration.hpplib/modules/sanitizer/SanitizerProvider.hpplib/modules/sanitizer/SanitizerProvider.cpplib/modules/sanitizer/SanitizerStringUtils.hpplib/modules/sanitizer/SanitizerStringUtils.cppPlatform Wrappers (6 files)
lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.javalib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.javalib/jni/Sanitizer_jni.cppwrappers/obj-c/ODWSanitizerInitConfig.hwrappers/obj-c/ODWSanitizerInitConfig.mmwrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swiftTests (2 files)
lib/modules/sanitizer/tests/unittests/SanitizerStringUtilsTests.cpplib/modules/sanitizer/tests/unittests/SanitizerProviderTests.cpp